#pragma once
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<netinet/tcp.h>
#include<unistd.h>
#include<fcntl.h>
#include<memory>
#include"InetAddress.h"
#include <netinet/tcp.h> 
#include <netinet/in.h>


namespace tmms
{
    namespace network
    {
        using InetAddressPtr = std::shared_ptr<InetAddress>;
        class SocketOpt //自己有一个sock，就是socket，所以BindAddress就是给sock绑定
        {
        public:
            SocketOpt(int sock,bool v6=false);
            ~SocketOpt() = default;

            static int CreateNonblockingTcpSocket(int family);
            static int createNonblockingUdpSocket(int family);

            //服务端接口
            int BindAddress(const InetAddress& localaddr);
            int Listen(); // ​​不阻塞​​：仅配置监听状态，调用后立即返回
            int Accept(InetAddress *peeraddr); //这个只能是先监听才可以Accept，会阻塞​​：若无新连接，线程将暂停在此处


            //客户端
            int Connetct(const InetAddress &addr);


            //通用接口
            InetAddressPtr GetLocalAddr();//获取套接字的​​本地地址信息
            InetAddressPtr GetPeerAddr();//获取套接字的​​对端地址信息​​
            void SetTcpNoDelay(bool on);
            void SetReuseAddr(bool on );
            void SetReusePort(bool on );
            void SetkeepAlive(bool on );
            void SetNooBlocking(bool on);

        private:
            int sock_{-1};
            bool is_ipv6_ {false};
        };
    }
}

